﻿/*
* ibio-develop
* Wed Oct 24 11:37:41 2007
*/

import mx.utils.Delegate;
import flash.filters.*;
class effect.Blur extends MovieClip{
	var m_filters_start:Number;
	var m_filters_end:Number;
	var m_filterDelta:Number = 0.4;
	var lj:BitmapFilter;
	var m_mc;
	var m_handleRun;
	var m_type:Boolean;
	var m_isRun:Boolean = true;
	
	function Blur(mc:MovieClip){
		m_mc = mc;
		lj = new BlurFilter(0, 0, 3);
		hide();
	}
	
	/*
	* blur:开始模糊的参数(0-255) 2 的乘方的值（如 2、4、8、16 和 32）呈现速度比其它值更快
	* type:true为 不可见→模糊→清晰, false为 清晰→模糊→不可见
	*/
	public function start( blur:Number,type:Boolean ) {
		m_type = type;
		if(m_type){
			m_filters_start = 0;
			m_filters_end = blur;
		}else{
			m_filters_start = blur;
			m_filters_end = 0;			
		}
		if(m_isRun){
			clearInterval(m_handleRun);
			pulse();
			m_mc._visible = true;
			m_handleRun = setInterval( Delegate.create( this , pulse ) , 60 );
			m_isRun = false;
		}
	}
	
	public function hide(){
		m_mc._visible = false;
	}
	
	public function show(){
		m_mc.filters = [];
		m_mc._visible = true;
	}
	
	private function pulse(){
		if (Math.abs(m_filters_start-m_filters_end)>1) {
			m_filters_end += (m_filters_start-m_filters_end)*m_filterDelta;
			lj['blurX'] = m_filters_end;
			lj['blurY'] = m_filters_end;
			m_mc.filters = [lj];
		}else {
			m_isRun = true;
			if(!m_type){
				hide();
			}
			clearInterval(m_handleRun);
		}
	}
}